layui.use(['element','form','upload','layer','slider','colorpicker'], function() {
    var $ = layui.jquery
        , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    var form = layui.form;
    var slider = layui.slider;
    var colorpicker = layui.colorpicker;
    var data = {};
    var layers = window.parent.jjsj_layers;

    //获取街景
    function jjsj(url) {
        var vars = url.split("&");
        var name;
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[1]) { name=pair[1]; }
        }
        return name;
    }
    //session数据获取
    var itemid = sessionStorage.getItem('itemid');
    var tag = sessionStorage.getItem('tag');
    var layerw = window.parent.sgworld.ProjectTree.getObject(itemid);
    var layertype = layerw.getType().value;
    var layerName = jjsj(layerw.treeobj.url);
    var layerData;
    for (var i = 0; i < layers.length; i++) {
        if (layers[i].url === layerName) {
            layerData=layers[i];
            break;
        }
    }

    //获取显示对象
    debugger
    var dx = ["polygonLayer", "polylineLayer", "Streetscape", "ImageryProvider", "polylineVolume", "pointLayer", "labelLayer", "billboard", "modelLayer", "3DTileset", "Streetscapes"];
    if (tag == "Streetscape") {
        debugger
        //街景的样式及属性
        pzshow(dx, "Streetscape");
        //属性添加
        //颜色调整
        colorpicker.render({
            elem: '#colorchk-jj'
            , color: (layerw.polylinemMterial == undefined ? "#ffffff" : layerw.polylinemMterial) //设置默认色
            , done: function (color) {
                if (color == undefined) return;
                layerw.polylinemMterial = color;
            }
        });
        //更改线宽度
        $('#lineWidth').on('input', function (event) {
            var value = $(this).val().replace(/[^\d\.]/g, '');
            if (value === '' || value === '.') return;
            layerw.polylineWidth = parseFloat(value);
        });
        //更改线宽度
        $('#linelx').on('input', function (event) {
            var value = $(this).val().replace(/[^\d\.]/g, '');
            if (value === '' || value === '.') return;
            layerw.polylinemArcType = parseFloat(value);
        });
        //更改线最大可视距离
        $('#polylineMaxView').on('input', function (event) {
            var value = $(this).val().replace(/[^\d\.]/g, '');
            if (value === '' || value === '.') return;
            var min = null;
            $('#polylineMinView').val() != '' ? min = Number($('#polylineMinView').val()) : min = 0;
            var max = value;
            layerw.polylineDistanceDisplayMaxCondition = new Cesium.DistanceDisplayCondition(min, max);
        });

        //更改线最小可视距离
        $('#polylineMinView').on('input', function (event) {
            var value = $(this).val().replace(/[^\d\.]/g, '');
            if (value === '' || value === '.') return;
            var max = null;
            $('#polylineMaxView').val() != '' ? max = Number($('#polylineMaxView').val()) : max = 100000000000;
            var min = value;
            layerw.polylineDistanceDisplayMinCondition = new Cesium.DistanceDisplayCondition(min, max);
        });

        //街景透明度
        slider.render({
            elem: '#opacity-streetscape'
            , min: 0 //最小值
            , max: 100 //最大值
            , value: layerData.alpha*100
            , change: function (value) {
                layerData.alpha = value / 100;

                if(parent.streetscape_layer===layerName||!parent.streetscape_layer){
                    window.parent.streetscape_alpha=value / 100;
                    window.parent.setOpacity(window.parent.streetscape_alpha);
                }
            }
        });
        data = {
            "lxxp": "街景"
            , "streetscapeArcType": layerw.polylinemArcType
            , "streetscapeWidth": layerw.polylineWidth
            , "streetscapeDistanceDisplayMaxCondition": layerw.polylineDistanceDisplayMaxCondition
            , "streetscapeDistanceDisplayMinCondition": layerw.polylineDistanceDisplayMinCondition
        };
    } else if (tag == "Streetscapes") {
        //街景的样式及属性
        pzshow(dx, "Streetscapes");
        //街景透明度
        slider.render({
            elem: '#opacity-streetscapes'
            , min: 0 //最小值
            , max: 100 //最大值
            , value: window.parent.streetscape_alpha * 100
            , change: function (value) {
                window.parent.streetscape_alpha = value / 100;
                window.parent.setOpacity(window.parent.streetscape_alpha);
            }
        });
    }else {
        if (layertype == "pointLayer") {
            //点的样式及属性
            pzshow(dx, layertype);
            //属性添加
            data = {
                "lxxp": "点" // 面类型
                , "pointOutlineWidth": layerw.pointOutlineWidth// 边框宽度
                , "pointPixelSize": layerw.pointPixelSize// 比例
                , "pointHeight": layerw.pointHeight// 高度
                , "pointHeightReference": layerw.pointHeightReference // 高度类型
                , "pointDistanceDisplayMaxCondition": layerw.pointDistanceDisplayMaxCondition // 最大可视距离
                , "pointDistanceDisplayMinCondition": layerw.pointDistanceDisplayMinCondition // 最小可视距离
            };
            //颜色调整
            colorpicker.render({
                elem: '#colorchk-point'
                , color: (layerw.pointColor == undefined ? "#ffffff" : layerw.pointColor) //设置默认色
                , done: function (color) {
                }
            });
            colorpicker.render({
                elem: '#colorchk-point2'
                , color: (layerw.pointOutlineColor == undefined ? "#ffffff" : layerw.pointOutlineColor) //设置边框颜色
                , done: function (color) {
                }
            });
        } else if (layertype == "ImageryProvider") {
            //影像的样式及属性
            pzshow(dx, "ImageryProvider");
            //属性添加
            data = {
                "lxxp": "影像"
                , "Iamgeurl": layerw.item.imageryProvider.url
                , "Iamgeshow": layerw.item.show
            };
        } else if (layertype == "TerrainProvider") {
            //影像的样式及属性
            pzshow(dx, "ImageryProvider");
            //属性添加
            data = {
                "lxxp": "地形"
                , "Iamgeurl": layerw.item._layers[0].resource.url
                , "Iamgeshow": layerw.item.show
            };
        } else if (layertype == "labelLayer") {
            //label的样式及属性
            pzshow(dx, layertype);
            //属性添加
            data = {
                "lxxp": "文本标签" // 面类型
                //, "labelText": layerw.labelText// 文本
                //, "labelText1s": layerw.getProperties()
                //, "labelStyles": layerw.labelStyles == undefined ? 0 : layerw.labelStyles// 样式
                , "labelOutlineWidth": layerw.labelOutlineWidth // 文本边框宽度
                , "labelFontSize": layerw.labelFontSize// 文本大小
                //, "labelBackground": layerw.labelBackground// 显示背景
                //, "labelHorizontalOrigin": layerw.labelHorizontalOrigin // 水平
                , "labelHeight": layerw.labelHeight // 高度
                , "heightReference": layerw.labelHeightReference// 高度
                , "labelVerticalOrigin": layerw.labelVerticalOrigin // 最小可视距离
                , "labelDistanceDisplayMaxCondition": layerw.labelDistanceDisplayMaxCondition // 最大可视距离
                , "labelDistanceDisplayMinCondition": layerw.labelDistanceDisplayMinCondition // 最小可视距离
            };
            //颜色调整
            colorpicker.render({
                elem: '#colorchk-labelFillColor'
                , color: (layerw.labelFillColor == undefined ? "#ffffff" : layerw.labelFillColor) //文本颜色
                , done: function (color) {
                }
            });
            colorpicker.render({
                elem: '#colorchk-labelOutlineColor'
                , color: (layerw.labelOutlineColor == undefined ? "#ffffff" : layerw.labelOutlineColor) //文本边框颜色
                , done: function (color) {
                }
            });
            colorpicker.render({
                elem: '#colorchk-labelBackgroundColor'
                , color: (layerw.labelBackgroundColor == undefined ? "#ffffff" : layerw.labelBackgroundColor) //背景色
                , done: function (color) {
                }
            });
        } else if (layertype == "3DTileset") {
            //label的样式及属性
            pzshow(dx, layertype);
            var dtilesetshadows = "对象不会投射或接收阴影";
            if (layerw.item.shadows == 0) {
                dtilesetshadows = "对象不会投射或接收阴影";
            } else if (layerw.item.shadows == 1) {
                dtilesetshadows = "对象投射和接收阴影";
            } else if (layerw.item.shadows == 2) {
                dtilesetshadows = "该对象仅投射阴影";
            } else if (layerw.item.shadows == 3) {
                dtilesetshadows = "对象仅接收阴影";
            }
            //属性添加
            data = {
                "lxxp": "3DTileset" // 3DTileset
                , "3dtileseturl": layerw.item.url// url
                , "3dtilesetshow": layerw.item.show//是否显示
                , "3dtilesetshadows": dtilesetshadows// shadows
            };

            //旋转角度
            $('#3dtilesetspin').on('input', function (event) {
                var value = $(this).val().replace(/[^\d\.]/g, '');
                if (value === '' || value === '.') return;
                layerw.setRotateZ(parseFloat(value));
                //layerw.polylineWidth = parseFloat(value);
            });
            //监听指定开关
            $('#btl1').click(function (layerw) {
                window.parent.sgworld.Creator.modelMove();
            });
            //form.on('switch(switchTest)', function (data) {
            //    layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
            //        offset: '6px'
            //    });
            //    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            //});
            ////平移（x轴）
            //$('#3dtilesetmoveX').on('input', function (event) {
            //});
            ////平移（y轴）
            //$('#3dtilesetmoveY').on('input', function (event) {
            //});
            ////平移（z轴）
            //$('#3dtilesetmoveZ').on('input', function (event) {
            //});

        } else if (layertype == "billboardLayer") {

        } else if (layertype == "modelLayer") {
            //model样式及属性
            pzshow(dx, layertype);
            //表单初始赋值
            var modelUri = layerw.modelUri;
            var modelScale = layerw.modelScale;
            var modelColor = layerw.modelColor;
            var modelHeight = layerw.modelHeight;
            var modelLightColor = layerw.modelLightColor;
            var modelHeightReference = (layerw.modelHeightReference == undefined ? 0 : layerw.modelHeightReference);
            var modelDistanceDisplayMaxCondition = layerw.modelDistanceDisplayMaxCondition;
            var modelDistanceDisplayMinCondition = layerw.modelDistanceDisplayMinCondition;
            data = {
                "lxxp": "模型" // 模型类型
                , "Modelpath": modelUri // 模型路径
                , "Modelproportion": modelScale  // 模型比例
                , "Modelheight": modelHeight// 模型高度
                , "modelExtrudedHeight": modelHeightReference// 模型高度类型
                , "Modelmax": modelDistanceDisplayMaxCondition // 最大可视距离
                , "Modelmin": modelDistanceDisplayMinCondition // 最小可视距离
            };
            //颜色调整
            colorpicker.render({
                elem: '#colorchk-model'
                , color: modelColor //设置默认色
                , done: function (color) {
                }
            });
            colorpicker.render({
                elem: '#colorchk-model2'
                , color: modelLightColor //设置默认色
                , done: function (color) {
                }
            });
        } else if (layertype == "polylineLayer") {
            return;
            //polylineLayer样式及属性
            pzshow(dx, layertype);
            //表单初始赋值
            var billboardImage = layerw.billboardImage;
            var billboardColor = layerw.billboardColor;
            var billboardScale = layerw.billboardScale;
            var billboardWidth = layerw.billboardWidth;
            var billboardPHeight = layerw.billboardPHeight;
            var billboardHeightReference = layerw.billboardHeightReference;
            var billboardDistanceDisplayMaxCondition = layerw.billboardDistanceDisplayMaxCondition;
            var billboardDistanceDisplayMinCondition = layerw.billboardDistanceDisplayMinCondition;
            form.val('example', {
                "lxxp": "线" // 面类型
                , "polylinemArcType": polylinemArcType // 线型
                , "polylineWidth": polylineWidth  // 线宽
                , "polylineDistanceDisplayMaxCondition": polylineDistanceDisplayMaxCondition// 最大可视距离
                , "polylineDistanceDisplayMinCondition": polylineDistanceDisplayMinCondition // 最小可视距离
            });
        } else if (layertype == "polylineVolume") {
            //线的样式及属性
            pzshow(dx, layertype);
            //表单初始赋值
            var polylineVolumeshow = layerw.billboardImage;
            var polylineVolumeoutlineWidth = layerw.billboardColor;
            data = {
                "lxxp": "扫掠体" // 模型类型
                , "polylineVolumeshow": layerw.item._entityCollection.values[0].polylineVolume.show._value // 模型路径
                , "polylineVolumeoutlineWidth": layerw.item._entityCollection.values[0].polylineVolume.outlineWidth._value  // 模型比例
            };
        } else if (layertype == "polylineWall") {
            //线的样式及属性
            pzshow(dx, "polylineVolume");
            //表单初始赋值
            //var polylineVolumeshow = layerw.billboardImage;
            //var polylineVolumeoutlineWidth = layerw.billboardColor;
            data = {
                "lxxp": "墙" // 模型类型
                , "polylineVolumeshow": layerw.item._entityCollection.show // 模型路径
                , "polylineVolumeoutlineWidth": layerw.item._entityCollection.values[0].wall.outlineWidth._value  // 模型比例
            };
        } else if (layertype == "polygonLayer") {
            //面的样式及属性polygonLayer
            pzshow(dx, layertype);
            //属性添加
            data = {
                "lxxp": "面" // 面类型
                , "polygonOutlineWidth": layerw.polygonOutlineWidth // 面边框宽度
                , "polygonHeight": layerw.polygonHeight  // 面高度
                , "polygonHeightReference": (layerw.polygonHeightReference == undefined ? 0 : layerw.polygonHeightReference)  // 面高度类型
                , "polygonExtrudedHeight": layerw.polygonExtrudedHeight// 面拉伸高度
                , "polygonExtrudedHeightReferenccolorchke": (layerw.polygonExtrudedHeightReference == undefined ? 0 : layerw.polygonExtrudedHeightReference)// 面拉伸高度
                , "polygonDistanceDisplayMaxCondition": layerw.polygonDistanceDisplayMaxCondition // 面最大可视距离
                , "polygonDistanceDisplayMinCondition": layerw.polygonDistanceDisplayMinCondition // 面最小可视距离
            };
            //颜色调整
            colorpicker.render({
                elem: '#colorchk-point'
                , color: (layerw.polygonMaterial == undefined ? "#ffffff" : layerw.polygonMaterial) //设置默认色
                , done: function (color) {
                }
            });
            colorpicker.render({
                elem: '#colorchk-point2'
                , color: (layerw.polygonOutlineColor == undefined ? "#ffffff" : layerw.polygonOutlineColor) //设置默认色
                , done: function (color) {
                }
            });
        }
    }
    form.val('example',data);

    //图层属性颜色选择器，input框，下拉框禁用
    $('.propDisabled').find('.colorchk').click(function () {
        $('.layui-colorpicker-main').hide();
    })
    $('.propDisabled').find('select').attr('disabled', 'disabled');
    form.render('select');
    $('.propDisabled').find('input').addClass('layui-disabled').attr('disabled', 'disabled');
    $('.propDisabled').find('.abled').removeClass('layui-disabled').removeAttr('disabled');
})
function pzshow(pz,cs) {
    for (var i = 0; i < pz.length; i++) {
        if (cs == pz[i]) {
            window.document.getElementById(pz[i]).style.display = 'block';
        } else {
            window.document.getElementById(pz[i]).style.display = 'none';
        }
    }
}